package com.tuniu.agents.tools.flights.utils;


import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

public class FlightCommonUtils {

    public static final String DOMESTIC_FLIGHT_SYSTEM_ID = "120";

    public static Map<String, String> analysisPriceInfoIdForTrans(String priceInfoId) {
        byte[] decodeBytes = Base64.getDecoder().decode(priceInfoId);
        String[] params = new String(decodeBytes, StandardCharsets.UTF_8).split("-");
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("vendorId", params[0].split("&")[0]);
        paramMap.put("cabinCode", params[0].split("&")[1] + "-" + params[1].split("&")[1]);
        return paramMap;
    }

    public static Map<String, String> analysisPriceInfoId(String priceInfoId) {
        byte[] decodeBytes = Base64.getDecoder().decode(priceInfoId);
        String[] params = new String(decodeBytes, StandardCharsets.UTF_8).split("&");
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("vendorId", params[0]);
        paramMap.put("cabinCode", params[1]);
        return paramMap;
    }

    public static Map<String, String> analysisPriceInfoForTurn(String priceInfoId) {
        byte[] decodeBytes = Base64.getDecoder().decode(priceInfoId);
        String[] params = new String(decodeBytes, StandardCharsets.UTF_8).split("#");
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("vendorId", params[0].split("&")[0]);
        paramMap.put("cabinCode", params[0].split("&")[1] + "#" + params[1].split("&")[1]);
        return paramMap;
    }

}
